﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Face.Web.VideoPage
{
    public partial class MyVideoAlbumsManage : System.Web.UI.Page
    {
        public string ThisUserName = "zjc";
        private static IBLL.IAlbum bllAlbum = BLLFactory.DataAccess.GetAlbum();


        protected void btn_logout(object sender, EventArgs e)
        {
            Session.Remove("user");
            Response.Redirect("/login_and_signup/login.aspx");
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
                ThisUserName = Session["user"].ToString();
            if (!IsPostBack)
            {
                bindDataToAlbum();

            }
        }

        protected void rpt_Album_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "btn_DeleteVideo")
            {
                bllAlbum.DeleteAlbum(System.Int32.Parse(e.CommandArgument.ToString()));
                bindDataToAlbum();
            }
            if (e.CommandName == "btn_RenameOK")
            {
                string kindID = e.CommandArgument.ToString().Split(',')[0];
                int itemIndex = Convert.ToInt32(e.CommandArgument.ToString().Split(',')[1]);
                System.Web.UI.HtmlControls.HtmlInputText inputText = this.Album_List.Items[itemIndex].FindControl("text_Rename") as System.Web.UI.HtmlControls.HtmlInputText;
                bllAlbum.RenameAlbumByAlbumID(System.Int32.Parse(kindID), inputText.Value);
                bindDataToAlbum();
            }
        }

        private void bindDataToAlbum()
        {
            //调用业务层
            Album_List.DataSource = bllAlbum.GetAlbumsByUsername(ThisUserName);
            Album_List.DataBind();
        }
    }
}